package com.bps.zzant.controller;


import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.bps.zzant.model.OrderGarment;
import com.bps.zzant.model.Payment;
import com.bps.zzant.model.ToDo;
import com.bps.zzant.services.OrderService;
import com.bps.zzant.services.ToDoService;


@Controller

public class GarmentOrderController extends ZzantController {
	private static final Logger logger = LoggerFactory.getLogger(GarmentOrderController.class);
	@Autowired
	private OrderService orderService;
	
	/* @RequestMapping(value = "/newgarmentorder", method = RequestMethod.GET) */
	@RequestMapping(value="/garmentorder", method = RequestMethod.GET)
	public String home(Locale locale, Model model, HttpServletRequest request) {
		//clear order items in the session and start a new order
		request.getSession().setAttribute("ORDER_ITEMS", null);
		logger.info("GarmentOrderController! the client locale is "+ locale.toString());
		return "garmentorder";
	}
	@RequestMapping(value = "editgarmentorder", method = RequestMethod.GET)
	public String getGarmentOrderById(Locale locale, Model model, HttpServletRequest request) {
		logger.info("************************GarmentOrderController.getGarmentOrderById : "+ request.getParameter("orderId"));
		// clear order items in session
		int orderId = Integer.parseInt(request.getParameter("orderId"));
		
		request.getSession().setAttribute("ORDER_ITEMS", null);
		OrderGarment order = orderService.getOrderById(orderId);

		request.getSession().setAttribute("ORDER_ITEMS", order.getGarmentItems());
		model.addAttribute("order", order);
	  return "displaygarmentorder"; 
	}
}
